<script setup lang="ts">
// 引入ref
import { ref, defineProps, defineEmits } from "vue"
import { useRouter } from "vue-router"
// 定义类型
interface tabType {
    path: string,
    title: string,
    img: string,
    img_active: string
    show: boolean
}

// 获取数据
const { tabList, idx } = defineProps(['tabList', 'idx'])
const emit = defineEmits(['handleClick'])

// 路由跳转
const router = useRouter()

// 点击切换路由
const handleTab = (item: tabType, index: number) => {
    // console.log(item, index);
    // // 赋值
    // idx.value = index
    // 传递参数
    emit("handleClick", index)
    // 跳转到指定页面
    router.push(item.path)
}
</script>

<template>
    <div class="box">
        <div v-for="(item, index) in tabList" :key="index" @click="handleTab(item, index)">
            <img :src="idx === index ? item.img_active : item.img" alt="">
            <p :class="idx === index ? 'active' : ''">{{ item.title }}</p>
        </div>
    </div>
</template>

<style scoped lang="scss">
.box {
    width: 50%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    overflow: hidden;
    border-radius: 30px 30px 0 0;

    cursor: pointer;

    >div {

        img {
            width: 40px;
            height: 40px;
        }

        p {
            margin: 0;
            padding: 0;

            font-size: 14px;
        }

        .active {
            color: #ffcd6b;
        }
    }
}
</style>